package cn.wolfcode.shop.server.service.impl;

import cn.wolfcode.shop.api.domain.CatalogProperty;
import cn.wolfcode.shop.api.service.ICatalogPropertyService;
import cn.wolfcode.shop.server.mapper.CatalogPropertyMapper;
import cn.wolfcode.shop.server.mapper.CatalogPropertyValueMapper;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CatalogPropertyServiceImpl implements ICatalogPropertyService {

    @Autowired
    private CatalogPropertyMapper catalogPropertyMapper;
    @Autowired
    private CatalogPropertyValueMapper catalogPropertyValueMapper;

    public CatalogProperty get(Long id) {
        return catalogPropertyMapper.selectByPrimaryKey(id);
    }

    public void update(CatalogProperty catalogProperty) {
        catalogPropertyMapper.updateByPrimaryKey(catalogProperty);
    }

    public void delete(Long id) {
        this.deleteRelation(id);
        catalogPropertyMapper.deleteByPrimaryKey(id);
    }

    public void deleteRelation(Long id) {
        catalogPropertyValueMapper.deleteRelation(id);
    }

    public void save(Long id, String name, Integer type) {
        CatalogProperty property = new CatalogProperty();
        property.setCatalogId(id);
        property.setName(name);
        property.setType(type);
        property.setSequence(0);
        catalogPropertyMapper.insert(property);
    }

    public List<Long> selectIdByCatalogId(Long catalogId) {
        return catalogPropertyMapper.selectIdByCatalogId(catalogId);
    }

    public List<?> getCatalogProperty(Long catalogId) {
        return catalogPropertyMapper.getCatalogProperty(catalogId);
    }

    public List getCatalogPropertyValue(Long id) {
        return catalogPropertyValueMapper.getCatalogPropertyValue(id);
    }
}
